package org.dtrd.config.wechat.entity.bean.officialaccount;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author qr
 * @date 2022/3/11 12:03
 */
@ApiModel("微信公众号一级菜单")
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class WechatMenuButton {

    @ApiModelProperty(value = "菜单标题，不超过16个字节，子菜单不超过60个字节", required = true)
    private String name;

    @ApiModelProperty(value = "菜单的响应动作类型，view表示网页类型，click表示点击类型，miniprogram表示小程序类型", required = true)
    private String type;

    @ApiModelProperty(value = "菜单KEY值，用于消息接口推送，不超过128字节", notes = "click等点击类型必须")
    private String key;

    @ApiModelProperty(value = "网页 链接，用户点击菜单可打开链接，不超过1024字节。 type为miniprogram时，不支持小程序的老版本客户端将打开本url。", notes = "view、miniprogram类型必须")
    private String url;

    @ApiModelProperty(value = "调用新增永久素材接口返回的合法media_id", notes = "media_id类型和view_limited类型必须")
    private String media_id;

    @ApiModelProperty(value = "小程序的appid（仅认证公众号可配置）", notes = "miniprogram类型必须")
    private String appid;

    @ApiModelProperty(value = "小程序的页面路径", notes = "小程序的页面路径")
    private String pagepath;

    @ApiModelProperty(value = "发布后获得的合法 article_id", notes = "article_id类型和article_view_limited类型必须")
    private String article_id;

    @ApiModelProperty("子菜单")
    private List<WechatMenuButton> sub_button;

    public WechatMenuButton() {}

    public WechatMenuButton(String name) {
        this.name = name;
    }

    public WechatMenuButton(String name, String type) {
        this.name = name;
        this.type = type;
    }

    public WechatMenuButton(String name, String type, String url) {
        this.name = name;
        this.type = type;
        this.url = url;
    }

    public void setSub_button(List<WechatMenuButton> sub_button) {
        this.sub_button = sub_button;
    }

    public void setSub_button(WechatMenuButton... sub_button) {
        int maxSubBtnNum = 5;
        List<WechatMenuButton> btns = new ArrayList<>(maxSubBtnNum);
        Collections.addAll(btns, sub_button);
        this.sub_button = btns;
    }

}
